Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dylib compilation and runtime loading #127

Merged
merged 19 commits into from
May 2, 2024
Merged

dylib compilation and runtime loading #127

merged 19 commits into from
May 2, 2024

Conversation

enricozb
Copy link
Contributor

@enricozb enricozb commented Apr 25, 2024

Fixes #112.

  1. Adds --dylib to the compile command. Per The Rust Reference, this will output a "*.so file on Linux, *.dylib file on macOS, and *.dll file on Window."
  2. Adds --include to the run command. A space-delimited list of hvm-core dynamic library files to load before running the provided hvm-core file.
  3. Fixes a bug where compiling an hvmc program that uses a single definition multiple times causes a rust error.

Additionally cleans up some clap args:

  • Changes filepaths from String to PathBuf.
  • Removes explicit short and long attributes if they are identical to the implicit ones.

Example:
two-and-three.hvmc:

@two = #2.0
@three = #3.0

two-plus-three.hvmc:

@main = r & @two ~ <f32.+ @three r>

Compiling and running:

$ cargo run -r -- compile two-and-three.hvmc --dylib --output two-and-three.so
$ cargo run -r -- run two-plus-three.hvmc --include two-and-three.so
#5.0
$ cargo run -r -- run two-plus-three.hvmc
thread 'main' panicked at src/host.rs:58:50:
Found reference "two", which is not in the book!
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fish: Job 1, 'cargo run -r -- run two-plus-th…' terminated by signal SIGABRT (Abort)

Notes

Generated dylibs are versioned with the hvmc crate version that was used to compile them. Using a dylib with a version of hvmc that does not match the dylib produces a warning like the following:

warning: dylib "f32-defs.dylib" was compiled with hvmc version 0.2.25, but is being run with hvmc version 0.2.26

@enricozb enricozb requested a review from tjjfvi April 25, 2024 12:37
@HigherOrderBot

This comment has been minimized.

@HigherOrderBot

This comment has been minimized.

src/stdlib.rs Outdated Show resolved Hide resolved
@HigherOrderBot

This comment has been minimized.

@HigherOrderBot

This comment has been minimized.

@HigherOrderBot

This comment has been minimized.

@HigherOrderBot

This comment has been minimized.

@enricozb enricozb marked this pull request as ready for review April 29, 2024 13:14
@enricozb enricozb requested a review from tjjfvi April 29, 2024 13:14
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Show resolved Hide resolved
@HigherOrderBot

This comment has been minimized.

@enricozb enricozb requested a review from tjjfvi April 29, 2024 14:13
@HigherOrderBot
Copy link
Collaborator

Perf run for f28c6ac:

file              mode        main          f28c6ac98277
========================================================
sum_tree          intr-singl      10.113 s      10.021 s
                  intr-multi       4.788 s       4.740 s
--------------------------------------------------------
sum_rec           intr-singl      14.854 s      14.221 s
                  intr-multi       7.622 s       7.589 s
--------------------------------------------------------
sum_tail          intr-singl       1.230 s       1.245 s
                  intr-multi       1.188 s       1.237 s
--------------------------------------------------------
c2                intr-singl       0.000 s       0.000 s
                  intr-multi       0.001 s       0.001 s
--------------------------------------------------------
boom              intr-singl       2.231 s       2.235 s
                  intr-multi       2.282 s       2.701 s
--------------------------------------------------------
bitonic_sort_lam  intr-singl      11.539 s      11.212 s
                  intr-multi       5.692 s       5.596 s
--------------------------------------------------------
merge_sort        intr-singl       7.570 s       7.304 s
                  intr-multi       3.896 s       3.691 s
--------------------------------------------------------
radix_sort_lam    intr-singl       9.794 s       9.778 s
                  intr-multi       4.959 s       4.839 s

@enricozb enricozb added this pull request to the merge queue May 2, 2024
Merged via the queue into main with commit 87e6056 May 2, 2024
6 checks passed
@enricozb enricozb deleted the enricozb/dylib branch May 2, 2024 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support compilation/loading of dynamic libraries
3 participants